/*
 * Copyright (C) 2011 Urals State University,
 * Department of Mathematics and Mechanics
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package ru.edu.usu.cs.bubbles.engine.box2d;

import ru.edu.usu.cs.bubbles.engine.Whirlpool;
import ru.edu.usu.cs.bubbles.engine.box2d.colliders.Collider;
import ru.edu.usu.cs.bubbles.utils.Point;

import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.physics.box2d.Body;
import com.badlogic.gdx.physics.box2d.BodyDef;
import com.badlogic.gdx.physics.box2d.CircleShape;
import com.badlogic.gdx.physics.box2d.Fixture;
import com.badlogic.gdx.physics.box2d.FixtureDef;

public class Box2dWhirlpool extends Whirlpool implements Box2dEntity {
	public final float forceAngle;
	private Body whirlpoolBody;
	private Collider collider = null;
	
	protected Box2dWhirlpool(Body body, float radius, float power) {
		super(radius, power);
		
		CircleShape whirlpoolShape = new CircleShape();
		whirlpoolShape.setRadius(radius);

		FixtureDef whirlpoolFixtureDef = new FixtureDef();
		whirlpoolFixtureDef.shape = whirlpoolShape;
		whirlpoolFixtureDef.isSensor = true;
		
		Fixture whirlPoolFixture = body.createFixture(whirlpoolFixtureDef);
		whirlPoolFixture.setGameEntity(this);
		whirlpoolShape.dispose();
		
		body.setType(BodyDef.BodyType.StaticBody);
		whirlpoolBody = body;
		forceAngle = MathUtils.atan2(1 / power, 1);
	}
	
	@Override
	public Point getPosition() {
		return whirlpoolBody.getPosition();
	}
	
	@Override
	public Body getBody() {
		return whirlpoolBody;
	}
	
	@Override
	public Collider getCollider() {
		return collider;
	}

	@Override
	public void setCollider(Collider collider) {
		this.collider = collider;
	}
}
